<?php /* Smarty version 2.6.12, created on 2011-07-18 08:10:47
         compiled from sample_edit.html */ ?>
<body>
<?php echo $this->_tpl_vars['xajax_scripts']; ?>
 
<form method='post' onsubmit='return check_form_pass();'><input type='hidden' name='op' value='sample_save'>
<div class='form_title'><?php echo @MI_SAMPLE_EDIT; ?>
</div>
  <br>
  <br>
  <table border='1' align="center" cellpadding='1' cellspacing='1' bordercolor="157fb9" class='form_detail'>
    <script>

var SampleIDVerified = false;
var PatientIDVerified = true;

function checkIsValidDate(str)
{
  if (str == "")
     return true;
  var pattern = /^(\d{4})\-(\d{1,2})\-(\d{1,2})$/g;
  if(!pattern.test(str))
     return false;
  var arrDate = str.split("-");
  if(parseInt(arrDate[0],10) < 100)
     arrDate[0] = 2000 + parseInt(arrDate[0],10) + "";
  var date = new Date(arrDate[0],(parseInt(arrDate[1],10) -1)+"",arrDate[2]);
  if(date.getYear() == arrDate[0]
     && date.getMonth() == (parseInt(arrDate[1],10)-1)+""
     && date.getDate() == arrDate[2])
     return true;
  else
     return false;
}

function set_lot_no_value(lot_no)
{
    var obj = document.getElementById("lot_no");

    if (lot_no == '')
        obj.selectedIndex = 0;
    else if (obj != null)
    {
        try
        {
            obj.selectedIndex = 0;
            for (var i=0; i<obj.options.length; i++)
                if (obj.options[i].innerText.match(lot_no+" "))
                {
                    obj.selectedIndex = i;
                    break;
                }
        }
        catch (e)
        {
        }
    }
}

function clear_sample(clear_sample_id)
{
    SampleIDVerified = false;

    if (clear_sample_id)
    {
        document.getElementById("sample_id").value = '';
        try { document.getElementById("sample_id").focus(); }
        catch (e) {}
    }

    document.getElementById("kit_id").value = '<?php echo $this->_tpl_vars['kit_id']; ?>
';
    document.getElementById("dna_ext_method").value = '';
    document.getElementById("dna_od").value = '';
    document.getElementById("comment").value = '';
    set_lot_no_value('<?php echo $this->_tpl_vars['lot_no']; ?>
');

    document.getElementById("sample_hint").style.display = 'none';
}

function hint_sample_id_wrong_format()
{
    document.getElementById('sample_hint').style.display = '';
    document.getElementById('sample_hint').innerHTML = "<font class='field_hint' style='background-color:red;'><?php echo @MI_SAMPLE_ID_WRONG_FORMAT; ?>
</font>";
}

function show_sample_not_exists()
{
    clear_sample();

    document.getElementById('sample_hint').style.display = '';
    document.getElementById('sample_hint').innerHTML = "<font class='field_hint'><?php echo @MI_SAMPLE_NOT_EXISTS; ?>
</font>";

    clear_patient(true);
}

function show_sample_exists(kit_id,sample_id,dna_ext_method,dna_od,lot_no,comment)
{
    clear_sample();

    document.getElementById('sample_hint').style.display = '';
    document.getElementById('sample_hint').innerHTML = "<font class='field_hint'><?php echo @MI_SAMPLE_EXISTS; ?>
</font>";

    if (document.getElementById("sample_id").value != sample_id)
        document.getElementById("sample_id").value = sample_id;

    document.getElementById("kit_id").value = kit_id;
    document.getElementById("dna_ext_method").value = dna_ext_method;
    document.getElementById("dna_od").value = dna_od;
    document.getElementById("comment").value = comment;
    set_lot_no_value(lot_no);
}

function clear_patient(clear_patient_id)
{
    PatientIDVerified = false;

    document.getElementById("patient_rowguid").value = 'false';

    if (clear_patient_id == true)
    {
        document.getElementById("institution").value = '<?php echo $this->_tpl_vars['institution']; ?>
';
        document.getElementById("patient_id").value = '';
    }

    document.getElementById("ethnic").value = '';
    document.getElementById("first_name").value = '';
    document.getElementById("last_name").value = '';
    document.getElementById("sex_M").checked = false;
    document.getElementById("sex_F").checked = false;
    document.getElementById("age").value = '';

    document.getElementById("patient_hint").style.display = 'none';
}

function hint_patient_id_wrong_format()
{
    document.getElementById('patient_hint').style.display = '';
    document.getElementById('patient_hint').innerHTML = "<font class='field_hint' style='background-color:red;'><?php echo @MI_PATIENT_ID_WRONG_FORMAT; ?>
</font>";
}

function show_patient_not_exists()
{
    clear_patient();

    document.getElementById('patient_hint').style.display = '';
    document.getElementById('patient_hint').innerHTML = "<font class='field_hint'><?php echo @MI_PATIENT_NOT_EXISTS; ?>
</font>";
}

function show_patient_exists(rowguid,institution,patient_id,ethnic,first_name,last_name,sex,age)
{
    document.getElementById("patient_rowguid").value = rowguid;

    if (document.getElementById("institution").value != institution)
        document.getElementById("institution").value = institution;

    if (document.getElementById("patient_id").value != patient_id)
        document.getElementById("patient_id").value = patient_id;

    document.getElementById('patient_hint').style.display = '';
    document.getElementById('patient_hint').innerHTML = "<font class='field_hint'><?php echo @MI_PATIENT_EXISTS; ?>
</font>";

    document.getElementById("ethnic").value = ethnic;
    document.getElementById("first_name").value = first_name;
    document.getElementById("last_name").value = last_name;

    document.getElementById("sex_M").checked = false;
    document.getElementById("sex_F").checked = false;

    if (sex == 'M')
        document.getElementById("sex_M").checked = true;
    else if (sex == 'F')
        document.getElementById("sex_F").checked = true;

    document.getElementById("age").value = age>0?age:'';
}

function do_add_lot(auto_focus)
{
    new_lot_no = document.getElementById("custom_add_lot_no").value;
    new_lot_expires = document.getElementById("custom_add_lot_expires").value;
    new_lot_expires = new_lot_expires.replace(/\//g, "-");

    if (new_lot_no == '' || new_lot_expires == '')
    {
        alert('<?php echo @MI_REQUIRE_LOT_DATA; ?>
');
        return false;
    }

    if (!checkIsValidDate(new_lot_expires))
    {
        alert('<?php echo @MI_INVALID_DATETIME_FORMAT; ?>
');
        return false;
    }

    for (var i=0; i<document.getElementById('lot_no').options.length; i++)
        if (document.getElementById('lot_no').options[i].innerText.replace(/\s-\s.*/, "") == new_lot_no)
        {
            document.getElementById('lot_no').selectedIndex = i;
            hide_add_lot(auto_focus);
            return true;
        }

    var objOption = new Option(new_lot_no + ' / <?php echo @MI_KIT_LOT_EXPIRES; ?>
 ' + new_lot_expires);
    document.getElementById('lot_no').options.add(objOption, 1);

    document.getElementById('lot_no').selectedIndex = 1;
    hide_add_lot(auto_focus);

    return true;
}

function show_add_lot(auto_focus)
{
    document.getElementById("custom_add_lot_no").value = '';
    document.getElementById("custom_add_lot_expires").value = '';
    document.getElementById("list_lot_block").style.display = 'none';
    document.getElementById("add_lot_block").style.display = '';
    if (auto_focus == true)
        document.getElementById("custom_add_lot_no").focus();
}

function hide_add_lot(auto_focus)
{
    document.getElementById("add_lot_block").style.display = 'none';
    document.getElementById("list_lot_block").style.display = '';
    if (auto_focus == true)
        document.getElementById('lot_no').focus();
}

function ServerSync_GetSampleInfo()
{
    if (document.getElementById("sample_id").value != '')
        xajax_Ajax_GetSampleInfo(document.getElementById("sample_id").value);
}

function ServerSync_GetPatientInfo()
{
    if (document.getElementById("institution").value == '')
        document.getElementById("institution").value = 'EMPTY';
    if (document.getElementById("patient_id").value != '')
        xajax_Ajax_GetPatientInfo(document.getElementById("institution").value, document.getElementById("patient_id").value);
}

function ServerSync_RefreshLotList()
{
    if (document.getElementById("kit_id").value != '')
        xajax_Ajax_RefreshLotList(document.getElementById("kit_id").value);
}

function check_form_pass()
{
    if (document.getElementById('institution').value == '')
        document.getElementById('institution').value = 'EMPTY';

    if (document.getElementById("add_lot_block").style.display == '')
    {
        if (document.getElementById("custom_add_lot_no").value != '')
        {
            if (!do_add_lot())
                return false;
        }
        else
            hide_add_lot();
    }

    if (document.getElementById('sample_id').value == '')
    {
        alert('<?php echo @MI_ERROR_REQUIRE_SAMPLE_ID; ?>
');
        document.getElementById('sample_id').focus();
        return false;
    }

    if (
        document.getElementById('patient_id').value != '' ||
        document.getElementById('ethnic').value != '' ||
        document.getElementById('first_name').value != '' ||
        document.getElementById('last_name').value != '' ||
        document.getElementById("sex_M").checked ||
        document.getElementById("sex_F").checked ||
        document.getElementById('age').value != '')
    {
        if (document.getElementById('institution').value == '' ||
            document.getElementById('patient_id').value == '' ||
            document.getElementById('first_name').value == '' ||
            document.getElementById('last_name').value == '')
        {
            alert('<?php echo @MI_ERROR_REQUIRE_PATIENT_INFO; ?>
');
            if (document.getElementById('institution').value == '')
                document.getElementById('institution').focus();
            else if (document.getElementById('patient_id').value == '')
                document.getElementById('patient_id').focus();
            else if (document.getElementById('first_name').value == '')
                document.getElementById('first_name').focus();
            else if (document.getElementById('last_name').value == '')
                document.getElementById('last_name').focus();
            return false;
        }
    }

    if (!SampleIDVerified)
    {
        ServerSync_GetSampleInfo();
        return false;
    }

    if (!PatientIDVerified)
    {
        ServerSync_GetPatientInfo();
        return false;
    }

    return true;
}

</script>
    <tr bordercolor="#cbe5f6"> 
      <td nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic03.jpg' style="color: black; font-size: 8pt; text-align: right;font-weight: bold;"><?php echo @MI_SAMPLE_ID; ?>
</td>
      <td> <input id='sample_id' size="20" maxlength=20 name='sample_id' value='' onfocus='clear_sample();' onkeypress='clear_sample();' onblur='ServerSync_GetSampleInfo();'> 
        <input type='hidden' name='sample_rowguid' value='false'> <div id='sample_hint' style='display:none;'></div></td>
      <td nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic03.jpg' style="color: black; font-size: 8pt; text-align: right;font-weight: bold;"><?php echo @MI_SELECT_KIT_ID; ?>
</td>
      <td> <select name='kit_id' onchange='ServerSync_RefreshLotList();'><?php $_from = $this->_tpl_vars['kit_id_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['kit_id'] => $this->_tpl_vars['kit_desc']):
?> <option value='<?php echo $this->_tpl_vars['kit_id']; ?>
'<?php if ($this->_tpl_vars['kit_id'] == $this->_tpl_vars['current_kit_id']): ?> selected<?php endif; ?>><?php echo $this->_tpl_vars['kit_id']; ?>
 - <?php echo $this->_tpl_vars['kit_desc']; ?>
</option> <?php endforeach; endif; unset($_from); ?> 
        </select></td>
    </tr>
    <tr bordercolor="#cbe5f6"> 
      <th nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic02.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><?php echo @MI_DNA_EXT_METHOD; ?>
</th>
      <td> <input size="20" maxlength=30 name='dna_ext_method' value=''></td>
      <th nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic02.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><?php echo @MI_DNA_OD; ?>
</th>
      <td> <input size="20" maxlength=12 name='dna_od' value=''></td>
    </tr>
    <tr bordercolor="#cbe5f6"> 
      <th nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic02.jpg' style="color: black; font-size: 8pt; text-align: right; "><?php echo @MI_KIT_LOT_NO; ?>
</th> 
      <td colspan=3><div id='list_lot_block'<?php if (count ( $this->_tpl_vars['lot_list'] ) == 0): ?> style='display:none;'<?php endif; ?>> 
        <select name='lot_no'>
          <option></option><?php $_from = $this->_tpl_vars['lot_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['line']):
?>
          <option<?php if ($this->_tpl_vars['lot_no'] == $this->_tpl_vars['line']['lot_no']): ?> selected<?php endif; ?>><?php echo $this->_tpl_vars['line']['lot_no']; ?>
 / <?php echo @MI_KIT_LOT_EXPIRES; ?>
 <?php echo $this->_tpl_vars['line']['lot_expires']; ?>
</option> <?php endforeach; endif; unset($_from); ?> 
        </select>
        <input type='button' class='sbutton' value="&nbsp;<?php echo @MI_ADD_LOT; ?>
&nbsp;" onclick='show_add_lot(true);'></div> <div id='add_lot_block'
        <?php if (count ( $this->_tpl_vars['lot_list'] ) > 0): ?> style='display:none;'<?php endif; ?>>
        <input size=20 maxlength=200 name='custom_add_lot_no' value=''>
        &nbsp;<?php echo @MI_KIT_LOT_EXPIRES; ?>

        <input size=10 maxlength=10 name='custom_add_lot_expires' value=''>
        &nbsp; <input type='button' class='sbutton' value="&nbsp;<?php echo @_ADD; ?>
&nbsp;" onclick='do_add_lot(true);'> 
        <input type='button' class='sbutton' value="&nbsp;<?php echo @_CANCEL; ?>
&nbsp;" onclick='hide_add_lot(true);'></div>
      </td>
    </tr>
    <tr bordercolor="#cbe5f6"> 
      <td nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic02.jpg' style="color: black; font-size: 8pt; text-align: right;font-weight: bold;"><?php echo @MI_COMMENT; ?>
</td>
      <td colspan=3> <textarea name='comment' cols=86 rows=5></textarea></td>
    </tr>
    <tr bordercolor="#cbe5f6" style='display:none;'> 
      <th nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic02.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><?php echo @MI_INSTITUTION; ?>
</th>
      <td colspan=3> <input size=70 maxlength=120 name='institution' value='<?php echo $this->_tpl_vars['institution']; ?>
'></td>
    </tr>
    <tr bordercolor="#cbe5f6"> 
      <td nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic03.jpg' style="color: black; font-size: 8pt; text-align: right;font-weight: bold;"><?php echo @MI_PATIENT_ID; ?>
</td>
      <td> <input size="20" maxlength=20 name='patient_id' value='' onfocus='clear_patient();' onkeypress='clear_patient();' onblur='ServerSync_GetPatientInfo();'> 
        <input type='hidden' name='patient_rowguid' value='false'> <div id='patient_hint' style='display:none;'></div></td>
      <td nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic03.jpg' style="color: black; font-size: 8pt; text-align: right;font-weight: bold;"><?php echo @MI_ETHNIC; ?>
</td>
      <td> <input size="20" maxlength=20 name='ethnic' value=''></td>
    </tr>
    <tr bordercolor="#cbe5f6"> 
      <th nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic02.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><?php echo @MI_FIRST_NAME; ?>
</th>
      <td> <input size="20" maxlength=50 name='first_name' value=''></td>
      <th nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic02.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><?php echo @MI_LAST_NAME; ?>
</th>
      <td> <input size="20" maxlength=50 name='last_name' value=''></td>
    </tr>
    <tr bordercolor="#cbe5f6"> 
      <th nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic02.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><?php echo @MI_SEX; ?>
</th>
      <td> <input type='radio' id='sex_M' name='sex' value='M'> <?php echo @_MALE; ?>
 
        &nbsp; <input type='radio' id='sex_F' name='sex' value='F'> <?php echo @_FEMALE; ?>
</td>
      <th nowrap background='<?php echo $this->_tpl_vars['theme_url']; ?>
/images/form_detail_pic02.jpg' style="color: black; font-size: 8pt; text-align: right; font-weight: bold;"><?php echo @MI_AGE; ?>
</th>
      <td> <input size="20" maxlength=3 name='age' value=''></td>
    </tr>
  </table>  
  <br>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td align="center">
<input name="submit" type='submit' class='btn_save' value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo @MI_SAVE; ?>
" /> 
        <input name="button" type='button' class='btn_clear' onClick='clear_sample();clear_patient(true);document.getElementById("sample_id").focus();' value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo @_CLEAR; ?>
" />
      </td>
    </tr>
  </table>
</form>
<script>
    clear_sample();
    clear_patient(true);
    document.getElementById('sample_id').focus();
</script>